home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / MainMenu.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  5.7 KB  |  284 lines  |  [TEXT/CWIE]

  1. { MainMenu.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit MainMenu;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     LowMem,
  15.     Menus,
  16.     TextEdit;
  17.  
  18. {----------}
  19. Procedure InitTitles;
  20. Procedure LoadMenus;
  21. Procedure DoMenu        (menuChoice:    longint);
  22. Procedure UpdateMenus;
  23.  
  24. {----------}
  25. Implementation
  26.  
  27. Uses
  28.     Devices,
  29.     Globals,
  30.     ResourceDefs,
  31.     Miscellany,
  32.     AMApp,
  33.     AMDoc,
  34.     AMEngine,
  35.     AMWindow;
  36.  
  37. {----------}
  38. Function  GetCommandFromMenu (
  39.     menuChoice:    longint): longint; Forward;
  40. Procedure DoApple (
  41.     itemNr:        integer); Forward;
  42.  
  43. {----------}
  44. Procedure InitTitles;
  45. Begin
  46. end; {InitTitles}
  47.  
  48. {----------}
  49. Procedure LoadMenus;
  50. Begin
  51.     AppleMenu    := GetMenu (MENU_Apple);
  52.     FailNilResource (Handle (AppleMenu));
  53.     AppendResMenu (AppleMenu, 'DRVR');
  54.     FileMenu    := GetMenu (MENU_File);
  55.     EditMenu    := GetMenu (MENU_Edit);
  56.     PopupMenu    := GetMenu (MENU_Popup);
  57.     ModalMenu    := GetMenu (MENU_Modal);
  58.     ModelessMenu    := GetMenu (MENU_Modeless);
  59.     BevelMenu    := GetMenu (MENU_Bevel);
  60.  
  61.     InsertMenu (AppleMenu, 0);
  62.     InsertMenu (FileMenu, 0);
  63.     InsertMenu (EditMenu, 0);
  64.     InsertMenu (ModalMenu, 0);
  65.     InsertMenu (ModelessMenu, 0);
  66.  
  67.     DrawMenuBar;
  68. end; {LoadMenus}
  69.  
  70. {----------}
  71. Procedure DoMenu (
  72.     menuChoice:        longint);
  73. var
  74.     commandID:        longint;
  75.     curDoc:            AMDoc;
  76.     menuID:            integer;
  77.     itemNr:            integer;
  78. begin
  79.     commandID := GetCommandFromMenu (menuChoice);
  80.     curDoc := cur.mDoc;
  81.     if cur.DoCommand (commandID) then begin
  82.         { cur window handled it }
  83.     end else if (curDoc <> nil)
  84.     & (curDoc.DoCommand (commandID)) then begin
  85.         { document handled it }
  86.     end else if gApplication.DoCommand (commandID) then begin
  87.         { application handled it }
  88.     end else begin
  89.         menuID := HiWrd (menuChoice);
  90.         itemNr := LoWrd (menuChoice);
  91.         if menuID = MENU_Apple then begin
  92.             DoApple (itemNr);
  93.         end;
  94.     end;
  95.     HiliteMenu (0);
  96. end; {DoMenu}
  97.  
  98. {----------}
  99. Function  GetCommandFromMenu (
  100.     menuChoice:        longint): longint;
  101. var
  102.     commandID:        longint;
  103. Begin
  104.     commandID := 0;
  105.  
  106.     case menuChoice of
  107.         cAppleAbout:
  108.                 commandID := cmdInvokeAbout;
  109.         cFileNew:
  110.                 commandID := cmdNew;
  111.         cFileOpen:
  112.                 commandID := cmdOpen;
  113.         cFileClose:
  114.                 commandID := cmdClose;
  115.         cFileSave:
  116.                 commandID := cmdSave;
  117.         cFileSaveAs:
  118.                 commandID := cmdSaveAs;
  119.         cFileRevert:
  120.                 commandID := cmdRevert;
  121.         cFilePageSetup:
  122.                 commandID := cmdPageSetup;
  123.         cFilePrint:
  124.                 commandID := cmdPrint;
  125.         cFileQuit:
  126.                 commandID := cmdQuit;
  127.         cEditUndo:
  128.                 commandID := cmdUndo;
  129.         cEditCut:
  130.                 commandID := cmdCut;
  131.         cEditCopy:
  132.                 commandID := cmdCopy;
  133.         cEditPaste:
  134.                 commandID := cmdPaste;
  135.         cEditClear:
  136.                 commandID := cmdClear;
  137.         cEditSelectAll:
  138.                 commandID := cmdSelectAll;
  139.         cEditShowClipboard:
  140.                 commandID := cmdShowClipboard;
  141.         cModalButtons:
  142.                 commandID := cmdModalButtons;
  143.         cModalCheckboxes:
  144.                 commandID := cmdModalCheckboxes;
  145.         cModalRadios:
  146.                 commandID := cmdModalRadios;
  147.         cModalText:
  148.                 commandID := cmdModalText;
  149.         cModalStuff:
  150.                 commandID := cmdModalStuff;
  151.         cModalMoreStuff:
  152.                 commandID := cmdModalMoreStuff;
  153.         cModelessButtons:
  154.                 commandID := cmdModelessButtons;
  155.         cModelessCheckboxes:
  156.                 commandID := cmdModelessCheckboxes;
  157.         cModelessRadios:
  158.                 commandID := cmdModelessRadios;
  159.         cModelessText:
  160.                 commandID := cmdModelessText;
  161.         cModelessStuff:
  162.                 commandID := cmdModelessStuff;
  163.         cModelessMoreStuff:
  164.                 commandID := cmdModelessMoreStuff;
  165.  
  166.         otherwise
  167.                 commandID := -menuChoice;
  168.     end;
  169.  
  170.     GetCommandFromMenu := commandID;
  171. End;
  172.  
  173. {----------}
  174. Procedure DoApple (
  175.     itemNr:            integer);
  176. var
  177.     name:            Str255;
  178.     refNum:            integer;
  179. Begin
  180.     GetMenuItemText (AppleMenu, itemNr, name);
  181.     refNum := OpenDeskAcc (name);
  182. End;
  183.  
  184. {----------}
  185. var
  186.     menu:                MenuHandle;
  187.     menuBarChanged:        Boolean;
  188.  
  189. {----------}
  190. Procedure Enable (
  191.     itemNr:        integer;
  192.     enabled:    Boolean);
  193. Begin
  194.     if enabled then begin
  195.         EnableItem  (menu, itemNr);
  196.     end else begin
  197.         DisableItem (menu, itemNr);
  198.     end;
  199. end; {Enable}
  200.  
  201. {----------}
  202. Procedure EnableTitle (
  203.     menu:        MenuHandle;
  204.     enabled:    Boolean);
  205. Begin
  206.     if enabled <> BTst (menu^^.enableFlags, 0) then begin
  207.         menuBarChanged := true;
  208.     end;
  209.     if enabled then begin
  210.         EnableItem  (menu, 0);
  211.     end else begin
  212.         DisableItem (menu, 0);
  213.     end;
  214. end; {EnableTitle}
  215.  
  216. {----------}
  217. Procedure UpdateMenus;
  218. var
  219.     frontPeek:        WindowPeek;
  220.     isFront:        Boolean;    {is there a front window?}
  221.     isCur:            Boolean;    {is there a current window?}
  222.     isCurDoc:        Boolean;    {is there a current document?}
  223.     isDirty:        Boolean;    {is it dirty?}
  224.     hasFile:        Boolean;    {does it have a file?}
  225.     isSelected:        Boolean;    {is anything selected?}
  226.     isDesk:            Boolean;    {is the front window a desk acc?}
  227.     isText:            Boolean;    {is there a current text field?}
  228.     isScrap:        Boolean;    {is there any scrap?}
  229.     curTE:            TEHandle;
  230. Begin
  231.     menuBarChanged := false;
  232.  
  233.     isFront        := (FrontWindow () <> nil);
  234.     isCur        := (curWindow <> nil);
  235.     isDirty        := false;
  236.     hasFile        := false;
  237.     isSelected    := false;
  238.     isCurDoc    := cur.mDoc <> nil;
  239.     if isCurDoc then begin
  240.         isDirty        := cur.mDoc.mEngine.IsDirty;
  241.         hasFile        := cur.mDoc.mEngine.HasFile;
  242.     end;
  243.  
  244.     isDesk := false;
  245.     if isFront then begin
  246.         frontPeek    := WindowPeek (FrontWindow);
  247.         isDesk        := (frontPeek^.windowKind < 0);
  248.     end;
  249.  
  250.     curTE := cur.GetCurTE;
  251.  
  252.     isText        := isCur & (curTE <> nil);
  253.     isScrap        := false;
  254.     if isText then begin
  255.         isSelected    := (curTE^^.selStart <> curTE^^.selEnd);
  256.         isScrap        := (TEGetScrapLength > 0);
  257.     end;
  258.  
  259.     menu := FileMenu;
  260.     Enable (cFileClose,            isFront);
  261.     Enable (cFileSave,            isDirty);
  262.     Enable (cFileSaveAs,        isCurDoc);
  263.     Enable (cFileRevert,        isDirty);
  264.  
  265.     menu := EditMenu;
  266.     if isFront then begin
  267.         Enable (cEditUndo,        isDesk);
  268.         Enable (cEditCut,        isDesk | isSelected);
  269.         Enable (cEditCopy,        isDesk | isSelected);
  270.         Enable (cEditPaste,        isDesk | isScrap);
  271.         Enable (cEditClear,        isDesk | isSelected);
  272.         Enable (cEditSelectAll,    isText);
  273.  
  274.     end;
  275.     EnableTitle (EditMenu,     isFront);
  276.  
  277.  
  278.     if menuBarChanged then begin
  279.         DrawMenuBar;
  280.     end;
  281. end; {UpdateMenus}
  282.  
  283. end.
  284.